<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title><?=getValInArr(getSess(SESS_DIC), array('webInfo', 'webtitle'))?></title>
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport"/>
    <meta content="yes" name="apple-mobile-web-app-capable"/>
    <meta content="black" name="apple-mobile-web-app-status-bar-style"/>
    <meta content="telephone=no" name="format-detection"/>
    <script src="<?php echo base_url() . 'public/home/js/' ?>jquery.js"></script>
    <?php
include_once "public/home/html/alert.php";
?>
    <script type="text/javascript" src="<?php echo base_url() . 'public/home/js/' ?>function.js"></script>
    <?php include_once "public/home/html/broadcast.php"?>
    <link rel="stylesheet" href="<?php echo base_url() . 'public/home/css/' ?>index.css">
    <?php include_once "public/home/html/bootstrap.php"?>
    <style>
        .search-border{
            background: #eaeaea;
            border-radius: 20px;
            height: 50px;
            margin-top: 50px;
        }
        .search-border img{
            width: 20px;
            margin-left: 20px;
        }
        .search-border input{
            height: 44px;
            margin-top: 3px;
            margin-left: 15px;
            border: none;
            background: #eaeaea;
            width: 80%;
        }
        .search-list div{
            line-height: 40px;
            text-align: center;
            border-bottom: 1px solid #ececec;
        }
    </style>
</head>
<body>
    <input type="hidden" name="url" id="url"value="<?php echo base_url() ?>">
    <input type="hidden" name="attend_id" id="attend_id" value="<?=$attend_id?>">
    <div class="search-border" oninput="getSearchList()">
        <img src="<?=base_url()?>public/home/images/search-icon.png">
        <input type="" name="" id="search" data-id="" placeholder="请输入教师名称">
    </div>
    <div class="search-list">

    </div>

    <script>
        getSearchList()
        $("body").keydown(function() {
            if (event.keyCode == "13") {//keyCode=13是回车键
                backSearch();
            }
         });
        // 获取搜索列表
        function getSearchList(){
            var type=$("#type").val();
            $.ajax({
                url: $("#url").val()+'Home/Search/getTeatcherList',
                type: 'POST',
                dataType: 'json',
                data: {
                    teacher_code: $("#search").val()
                },
                success:function(data){
                    var t=JSON.parse(data.v);
                    if(data.status){
                        var html='';
                        $.each(t, function(k, v) {
                             html+="<div onclick='getValue(this)' data-value='"+v['username']+"' data-id='"+v['id']+"'>";
                             if(v['usercode']){
                                html+="【"+v['usercode']+"】";
                             }
                             html+=v['username']+"--"+v['dept_name']+"</div>";
                        });
                        $(".search-list").html(html);
                    }
                }
            })
        }

        // 点击搜索列表值，赋值到input上
        function getValue(obj){
            $("#search").val($(obj).attr('data-value'));
            $("#search").attr('data-id',$(obj).attr('data-id'));
            // var teacher_id=$(obj).attr('data-id');
            // var href=getRootPath()+'/Home/Class_Assess/Index/'+$("#attend_id").val()+'/'+teacher_id;
            // location.href=href;
            $.ajax({
                url: $("#url").val()+'Home/Search/setTeacher',
                type: 'POST',
                dataType: 'json',
                data: {
                    teacher_id: $(obj).attr('data-id')
                },
                success:function(data){
                    var t=JSON.parse(data.v);
                    if(data.status){
                        // window.history.go(-1);
                        var href=getRootPath()+'/Home/Class_Assess/Index/'+$("#attend_id").val()+'?next=1';
                        location.href=href;
                    }
                }
            })
        }
    </script>

</body>
</html>
